package com.servlet;

import com.alibaba.fastjson.JSON;
import com.pojo.text;
import com.pojo.user;
import com.service.textService;
import com.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(value = "/text_SelectAll")
public class text_SelectAll extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

        textService t = new textService();

        List<text> texts = t.textselectAll();

        //转化为json格式
        String text_json = JSON.toJSONString(texts);

        //设置响应格式
        res.setContentType("text/json;Charset=utf-8");
        //后端发JSON串，前端then里的响应数据是json数组
        res.getWriter().write(text_json);


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
